﻿using System.Text.RegularExpressions;
using System;

namespace XExcel.Validations
{
    public abstract class Validate : IValidate
    {
        public string Message { get; protected set; }
        public abstract bool Test(object val);
        public static MuiltValidate Muilt()
        {
            return new MuiltValidate();
        }
        public static IValidate Regex(string pattern, string message = null)
        {
            return new RegexValidate(pattern, message);
        }
        public static IValidate Regex(Regex regex, string message = null)
        {
            return new RegexValidate(regex, message);
        }
        public static IValidate DateRange(DateTime? datemin = null, DateTime? datemax = null, string message = null)
        {
            if(datemin == null && datemax == null && message == null)
            {
                return DateRangeValidate.Default;
            }
            else
            {
                return new DateRangeValidate(datemin, datemax, message);
            }
        }
        public static IValidate NotNull(string message = null)
        {
            if(message == null)
            {
                return NotNullValidate.Default;
            }
            else
            {
                return new NotNullValidate(message);
            }
        }
        public static IValidate Function(Func<object, bool> valid, string message = null)
        {
            return new FunctionValidate(valid, message);
        }
    }
}
